<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="shortcut icon" href="http://yangwenxue.oschina.io/images/favicon.ico">
		<link rel="stylesheet" href="http://yangwenxue.oschina.io/css/font-awesome.min.css" type="text/css">
		<link rel="stylesheet" href="http://yangwenxue.oschina.io/css/theme.css" type="text/css"> </head>

	<body>
		<div class="py-5">
			<div class="container">
				<div class="row">
					<div class="col-md-12">
						<img src="http://yangwenxue.oschina.io/images/user-1.jpg" id="userImageUrl" class="rounded-circle img-fluid mx-auto d-block">
					</div>
				</div>
				<div class="row">
					<div class="col-md-12">
						<ul class="list-group">
							<li class="list-group-item text-center"><span id="userName">大脸猫</span> </li>
							<li class="list-group-item text-center">年龄：<span id="age">25</span></li>
							<li class="list-group-item text-center">性别：<span id="userSex">男</span></li>
							<li class="list-group-item text-center">等级：<span id="userRankId">99</span></li>
							<li class="list-group-item text-center">邮箱：<span id="userEmail">18515161858@139.com</span></li>
							<li class="list-group-item text-center">积分：<span id="userMark">0</span></li>
							<li class="list-group-item text-center">毕业院校：<span id="userSchool">北京理工大学</span></li>
							<li class="list-group-item text-center">地址：<span id="userAddress">北京昌平</span></li>
							<li class="list-group-item text-center">注册时间：<span id="userRegisterTime">2017-07-01</span></li>
							<li class="list-group-item text-center">描述：<span id="userDescription">我是李嘉诚，12岁就开始做学徒，还不到15岁就挑起了一家人的生活担子，再没有受到过正规的教育。当时自己非常清楚，只有我努力工作和求取知识，才是我唯一的出路。我有一点钱我都去买书，记在脑子里面，才去再换另外一本。到我今天来讲，每一个晚上，在我睡觉之前，我还是一定得看书。知识并不决定你一生是否有财富增加，但是你的机会就更加多了，你创造机会才是最好的途径</span></li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<script src="http://yangwenxue.oschina.io/js/jquery/jquery.min.js"></script>
		<script src="http://yangwenxue.oschina.io/js/tether.min.js"></script>
		<script src="http://yangwenxue.oschina.io/js/boostrap/bootstrap-4.0.0-alpha.6.min.js"></script>
		<script src="../js/common.js"></script>
	</body>
	<script type="text/javascript">
		$(function() {
			$.ajax({
				type: "post",
				url: resPath + "user/info",
				dataType: 'json',
				success: function(result) {
					var status = parseInt(result.status);
					switch(status) {
						case 200:
							var imageUrl = result.data.userImageUrl;
							if(imageUrl != null && imageUrl != '' && imageUrl != undefined){
								$("#userImageUrl").attr("src",imageUrl);
							}
							$("#userName").val(result.data.userName);
							$("#userRankId").val(result.data.userRankId);
							$("#userSex").val(result.data.userSex);
							$("#userEmail").val(result.data.userEmail);
							$("#userMark").val(result.data.userMark);
							$("#userSchool").val(result.data.userSchool);
							$("#userAddress").val(result.data.userAddress);
							$("#userRegisterTime").val(new Date(result.data.userRegisterTime).Format("yyyy-MM-dd"));
							$("#userDescription").html(result.data.userDescription);

							// 给日期类对象添加日期差方法，返回日期与diff参数日期的时间差，单位为天
							Date.prototype.diff = function(date) {
								return(this.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
							}
							// 构造两个日期，分别是系统时间和2013/04/08 12:43:45
							var now = new Date();
							// 调用日期差方法，求得参数日期与系统时间相差的天数
							var diff = now.diff(new Date(result.data.userBirthday));
							$("#age").html(Math.ceil(diff));
							break;
						case 2001:
							alert(result.msg);
							window.location.href = "http://yangwenxue.oschina.io/index.html";
							break;
						default:
							alert("操作失败，请重新试试");
							break;
					}
				},
				error: function(err) {
					alert("网络错误,获取用户信息失败");
					window.location.href = "http://yangwenxue.oschina.io/index.html";
				}
			});
		});
	</script>
</html>